package client;

import java.rmi.Naming;
import java.rmi.RemoteException;
import java.util.HashMap;
import java.util.Set;



import server.IServer;
import subject.ISubject;

public class Client {
	private IServer server = null;
	private String identifiant;
	private HashMap<String, ISubject> subjects;

	private Client(String id) {
		subjects = new HashMap<String, ISubject>();
		identifiant = id;
	}

	public void setServer(IServer aServer) {
		server = aServer;
	}

	public IServer getServer() {
		return server;
	}

	public boolean createSubject(String name) {
		return false;
	}

	/**
	 * @param nameSubject
	 * @throws Exception
	 */
	public void connectSubject(String nameSubject) throws Exception {
		try {
			server.connectSubject(nameSubject, identifiant);
			subjects.put(nameSubject, server.getSubject(nameSubject));
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	public String getIdentifiant() {
		return identifiant;
	}

	public void setIdentifiant(String identifiant) {
		this.identifiant = identifiant;
	}

	public Set<String> getSubject() {

		return server.getSubjects();
	}

	public static void main(String[] argv) throws Exception {
		IServer server;
		Client c = new Client("joe");
		Client c1 = new Client("joe2");
		server = (IServer) Naming.lookup("//localhost/RmiServer");

		// c.connectSubject("Cinema");
		System.out.println("Server");
		c.setServer(server);
		c1.setServer(server);
		ISubject subject = c.getServer().getSubject("Cinema");
		 ISubject subject1 = c.getServer().getSubject("Cinema");
	}

}
